Skip to content

Conversation

@bukas898
Copy link

Summary

This PR refactors the streaming payment contract to use day-based timing instead of block-based timing, making the contract more intuitive for end users while maintaining the same underlying functionality and security guarantees.

Motivation

The original implementation required users to think in terms of blocks (e.g., "stream for 4,320 blocks"), which is not intuitive for non-technical users. By abstracting to days, we provide a better user experience without sacrificing precision or security.

Changes Made

Core Modifications

  • Added get-current-day() helper function: Converts block-height to days using the approximation of 144 blocks per day
  • Renamed timing parameters:
    • payment-per-blockpayment-per-day
    • start-block/stop-blockstart-day/end-day
  • Updated calculation function: calculate-block-deltacalculate-day-delta with day-based logic
  • Modified all function signatures: Updated stream-to, hash-stream, and update-details to accept day-based parameters

Files Changed

  • streaming-payment.clar (all timing-related functions and data structures)

Technical Details

  • Uses integer division (/ block-height u144) to convert blocks to days
  • Assumes ~144 blocks per day (Stacks average block time)
  • All balance calculations remain precise at the block level
  • No changes to security model or authorization logic

Testing Considerations

  • Verify day calculations align with block timing
  • Test edge cases around day boundaries
  • Confirm withdraw and refund operations work correctly
  • Validate signature verification for update-details with new parameters

Impact

  • User Experience: ✅ Significantly improved - users can now think in familiar time units
  • Gas Costs: ➡️ No change - same number of operations
  • Security: ➡️ No change - authorization and validation logic unchanged
  • Precision: ➡️ Maintained - still uses block-height internally

Example Usage

Before:

(stream-to recipient u1000 {start-block: u100, stop-block: u4420} u0.23)
;; Pay 0.23 STX per block for 4,320 blocks

After:

(stream-to recipient u1000 {start-day: u1, end-day: u31} u100)
;; Pay 100 STX per day for 30 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants